package com.shm.xunlei;

import jdk.nashorn.internal.ir.Flags;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author: shm
 * @dateTime: 2020/10/21 9:05
 * @description: 重建链表
 */
public class Main {
    public static void main(String[] args) {
        Scanner input =  new Scanner(System.in);
        String s = input.nextLine();
        int n = Integer.parseInt(s);
        String[][] arr = new String[n-1][2];
        HashMap<String,String> map = new HashMap<>();
        for (int i = 0; i < n-1; i++) {
            String str = input.nextLine();
            String[] ss = str.split(" ");
            arr[i][0] = ss[0];
            arr[i][1] = ss[1];
            map.put(arr[i][0],arr[i][1]);
        }

//        HashMap<String,String> map = new HashMap<>();
//        for (int i = 0; i < arr.length; i++) {
//            map.put(arr[i][0],arr[i][1]);
//        }

        String start = arr[0][0];
        for (int i = 0; i < n-1; i++) {
            start = arr[i][0];
            boolean flag = true;
            for (int j = 0; j < n-1; j++) {
                if (arr[j][1]==arr[i][0]){
                    flag=false;
                }
            }
            if (flag){
                break;
            }
        }
        System.out.println(start);
        String cur = start;
        for (int i = 0; i < n-1; i++) {
            String next = map.get(cur);
            cur = next;
            System.out.println(next);
        }
    }
}
